//Jeff Chastine #include #include #include #include using namespace std; void changeViewPort(int w, int h) { glViewport(0, 0, w, h); } void render() { glClearColor(1.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // glLineWidth(4.0); GLfloat x = -1.0, y; int draw = 0; glBegin(GL_LINES); glColor3f(1.0, 1.0, 1.0); // Tr?c hoành glVertex2f(-1.0, 0); glVertex2d(1.0, 0); // Tr?c tung glVertex2d(0, -1.0); glVertex2d(0, 1.0); glEnd(); glBegin(GL_LINES); glColor3f(1.0, 1.0, 1.0); while (x < 1.0) { y = 0.5 * sin(x * 4); draw++; if (draw % 3 == 0) { glVertex2f(x, y); glVertex2f(x, 0); } x += 0.01; } glEnd(); x = -1.0; glBegin(GL_LINE_STRIP); glColor3f(0.0, 0.0, 1.0); while (x < 1.0) { y = 0.5 * sin(x * 4); glVertex2f(x, y); x += 0.01; } glEnd(); glutSwapBuffers(); } int main(int argc, char* argv[]) { // Initialize GLUT glutInit(&argc, argv); // Set up some memory buffers for our display glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); // Set the window size glutInitWindowSize(600, 600); // Create the window with the title "Hello,GL" glutCreateWindow("Beginning OpenGL"); // Bind the two functions (above) to respond when necessary glutReshapeFunc(changeViewPort); glutDisplayFunc(render); // Very important! This initializes the entry points in the OpenGL driver so we can // call all the functions in the API. GLenum err = glewInit(); if (GLEW_OK != err) { fprintf(stderr, "GLEW error"); return 1; } glutMainLoop(); return 0; }